<template>
  <div id="box-home">
    <div class="banner">
      <!-- 首页轮播图 -->
      <HomeBanner></HomeBanner>
      <!-- 轮播图侧边栏 -->
      <LeftRig></LeftRig>
    </div>

    <!-- 首页新鲜好物 -->
    <div class="fresh conment">
      <div class="head">
        <h3>新鲜好物<small>新鲜出炉 品质靠谱</small></h3>
        <a href="#/" class="">
          <span>查看全部</span>
          <i class="el-icon-arrow-right"></i>
        </a>
      </div>

      <ul>
        <li v-for="item in fresh" :key="item.id" @click="freshs(item.id)">
          <img :src="item.picture" alt="" />
          <p>{{ item.name }}</p>
          <p><i>￥</i>{{ item.price }}</p>
        </li>
      </ul>
    </div>

    <!-- 首页推荐好物 -->
    <div class="panel conment">
      <div class="head">
        <h3>人气推荐<small>人气爆款 不容错过</small></h3>
        <a href="#/" class="">
          <span>查看全部</span>
          <i class="el-icon-arrow-right"></i>
        </a>
      </div>
      <ul>
        <li v-for="item in panel" :key="item.id">
          <img :src="item.picture" alt="" />
          <p>{{ item.title }}</p>
          <p>{{ item.alt }}</p>
        </li>
      </ul>
    </div>

    <!-- 首页热门品牌 -->
    <div id="boxs">
      <div class="long">
        <div class="long-top">
          <h3>热门品牌<small>国际经典 品质保证</small></h3>
          <a class="el-icon-arrow-left" @click="left" ref="left_a"></a>
          <a class="el-icon-arrow-right" @click="right" ref="right_a"></a>
        </div>
        <div class="long-bottom" ref="long_bottom">
          <img :src="item.picture" alt="" v-for="item in boxs" :key="item.id" />
        </div>
      </div>
    </div>

    <!-- 首页产品区块 -->
    <div class="home-product">
      <div class="container" v-for="item in goods" :key="item.id">
        <div class="container">
          <div class="head">
            <h3>{{ item.name }}<small></small></h3>
            <div class="sub">
              <a v-for="items in item.children" :key="items.id">{{
                items.name
              }}</a>
            </div>
            <a class="xtx-more">
              <span>查看全部</span>
              <i class="iconfont el-icon-arrow-right"></i>
            </a>
          </div>
          <div class="box">
            <a class="cover">
              <img alt="" :src="item.picture" @click="covr(item.id)"/>
              <strong class="label">
                <span>{{ item.name }}馆</span>
                <span>3折起狂欢</span>
              </strong>
            </a>
            <ul class="goods-list">
              <li v-for="itemg in item.goods" :key="itemg.id">
                <div class="goods-item">
                  <a class="image">
                    <img v-lazy="itemg.picture" alt="" @click="covr(itemg.id)"/>
                  </a>
                  <p class="name ellipsis-2">{{ itemg.name }}</p>
                  <p class="desc ellipsis">{{ itemg.desc }}</p>
                  <p class="price">{{ itemg.price }}</p>
                  <div class="extra">
                    <a class="router-link-active router-link-exact-active">
                      <span>找相似</span>
                      <span>发现现多宝贝 &gt;</span>
                    </a>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <!-- 首页最新专题 -->
    <div class="tit">
      <div class="conment">
        <div class="head">
        <h3>最新专题</h3>
        <a href="#/" class="">
          <span>查看全部</span>
          <i class="el-icon-arrow-right"></i>
        </a>
      </div>
      <ul class="special-list">
        <li class="special-item" v-for="item in tit" :key="item.id">
          <a>
            <img :src="item.detailsUrl" alt=""/>
            <div class="meta">
              <p class="title">
                <span class="top ellipsis">{{item.title}}</span>
                <span class="sub ellipsis">{{item.summary}}</span>
              </p>
              <span class="price">￥{{item.lowestPrice}}</span>
            </div>
          </a>
          <div class="foot">
            <span class="like" >
              <i class="iconfont el-icon-cherry" ></i>{{item.collectNum}}
            </span>
            <span class="view">
              <i class="iconfont el-icon-apple"></i>{{item.viewNum}}
            </span>
            <span class="reply">
              <i class="iconfont el-icon-ice-cream-round"></i>{{item.replyNum}}
            </span>
          </div>
        </li>
      </ul>
      </div>
    </div>
  </div>

</template>

<script>
// 引入公共组件轮播图
import HomeBanner from "@/components/HomeBanner.vue";
// 引入公共组件轮播图侧面的黑色二级菜单
import LeftRig from "@/components/LeftRig.vue";
// 引入首页接口
import { fresh, panel, boxs, goods, tit } from "@/api/user";

export default {
  name:"HomePage",
  components: {
    HomeBanner,
    LeftRig,
  },
  data() {
    return {
      fresh: [],
      panel: [],
      boxs: [],
      goods: [],
      tit:[]
    };
  },

  mounted() {
    // 新鲜好物数据
    fresh().then((res) => {
      this.fresh = res.data.result;
    });
    // 人气推荐数据
    panel().then((res) => {
      this.panel = res.data.result;
    });
    // 热门品牌数据
    boxs().then((res) => {
      this.boxs = res.data.result;
    });
    // 产品区块数据
    goods().then((res) => {
      this.goods = res.data.result;
    });
    tit().then((res) => {
      this.tit = res.data.result;
    });
  },
  methods: {
    left() {
      this.$refs.long_bottom.style.transform = "translateX(0px)";
    },

    right() {
      this.$refs.long_bottom.style.transform = "translateX(-1240px)";
    },

    // 新鲜好物跳转详情页
    freshs(id){
      this.$router.push({path: "/NaviGation/PartiCulars",query: {id:id },});
    },

    // 产品区块跳转详情页
    covr(id){
      this.$router.push({path: "/NaviGation/PartiCulars",query: {id:id },});
    }
  },
};

</script>

<style scoped>

* {
  box-sizing: border-box;
}

#box-home {
  background: #fff;
}

.banner {
  width: 1240px;
  height: 500px;
  position: relative;
  margin: 0 auto;
}

/* 新鲜好物 */
.conment {
  width: 1240px;
  margin: 0 auto;
  position: relative;
}

.head {
  padding: 40px 0;
  display: flex;
  align-items: flex-end;
}

.head h3 {
  flex: 1;
  font-size: 32px;
  font-weight: 400;
  margin-left: 6px;
  height: 35px;
  line-height: 35px;
}

.fresh .head h3 small,
.panel .head h3 small {
  font-size: 16px;
  color: #999;
  margin-left: 20px;
}

.head a{
  margin-bottom: 2px;
}

.head a span {
  font-size: 16px;
  vertical-align: middle;
  margin-right: 4px;
  color: #999;
}

.head a i{
  font-size: 14px;
  vertical-align: middle;
  position: relative;
  top: 2px;
  color: #ccc;
}

.fresh ul,
.panel ul {
  display: flex;
  justify-content: space-between;
  height: 406px;
}

.fresh ul li {
  width: 306px;
  height: 406px;
  background: #f0f9f4;
  transition: all 0.5s;
  cursor: pointer;
}

.fresh ul li:hover,
.panel ul li:hover {
  transform: translate3d(0, -3px, 0);
  box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
}

.fresh ul li img,
.panel ul li img {
  width: 306px;
  height: 306px;
}

.fresh ul li p,
.panel ul li p {
  font-size: 22px;
  padding: 12px 30px 0 30px;
  text-align: center;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.fresh ul li p:nth-child(3) {
  color: #cf4444;
  font-size: 22px;
  padding: 12px 30px 0 30px;
  text-align: center;
}

.panel ul li {
  width: 306px;
  height: 406px;
  transition: all 0.5s;
  cursor: pointer;
}

.panel ul li p:nth-child(2) {
  font-size: 22px;
  padding-top: 12px;
  text-align: center;
}

.panel ul li p:nth-child(3) {
  color: #999;
  font-size: 18px;
}

#boxs {
  width: 100%;
  margin: 0 auto;
  position: relative;
  background: #f5f5f5;
}

.long {
  width: 1240px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
}

.long-top {
  padding: 40px 0;
  display: flex;
  align-items: flex-end;
}

.long-top > h3 {
  flex: 1;
  font-size: 32px;
  font-weight: 400;
  margin-left: 6px;
  height: 35px;
  line-height: 35px;
}

.long-top > h3 > small {
  font-size: 16px;
  color: #999;
  margin-left: 20px;
}

.long-top > a {
  width: 20px;
  height: 20px;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: #27ba9b;
  line-height: 20px;
}

.long-bottom {
  display: flex;
  width: 100%;
  height: 345px;
  padding-bottom: 40px;
  transition: all 1s;
}

.long-bottom > img {
  width: 240px;
  height: 305px;
  margin-right: 10px;
}

.home-product {
  background: #fff;
}

.home-product .head {
  padding: 40px 0;
  display: flex;
  align-items: flex-end;
}

.home-product .head h3 {
  flex: 1;
  font-size: 32px;
  font-weight: 400;
  margin-left: 6px;
  height: 35px;
  line-height: 35px;
}

.home-product .head h3 small {
  font-size: 16px;
  color: #999;
  margin-left: 20px;
}

.home-product .sub {
  margin-bottom: 2px;
}

.home-product .sub a {
  padding: 2px 12px;
  font-size: 16px;
  border-radius: 4px;
}

.home-product .sub a:hover {
  background: red;
  color: #fff;
}

.home-product .sub a:last-child {
  margin-right: 80px;
}

.xtx-more {
  margin-bottom: 2px;
}

.xtx-more span {
  font-size: 16px;
  vertical-align: middle;
  margin-right: 4px;
  color: #999;
}

.xtx-more i {
  font-size: 14px;
  vertical-align: middle;
  position: relative;
  top: 2px;
  color: #ccc;
}

.home-product .box {
  display: flex;

}

.home-product .box .cover {
  width: 240px;
  height: 610px;
  margin-right: 10px;
  position: relative;
}

.home-product .box .cover img {
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
  object-fit: cover;
}

.home-product .box .cover .label {
  width: 188px;
  height: 66px;
  display: flex;
  font-size: 18px;
  color: #fff;
  line-height: 66px;
  font-weight: 400;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate3d(0, -50%, 0);
}

.home-product .box .cover .label span:first-child {
  width: 76px;
  background: rgba(0, 0, 0, 0.9);
}

.home-product .box .cover .label span:last-child {
  flex: 1;
  background: rgba(0, 0, 0, 0.7);
}

.home-product .box .cover .label span {
  text-align: center;
}

.home-product .box .goods-list {
  width: 990px;
  display: flex;
  flex-wrap: wrap;
}

.home-product .box .goods-list li {
  width: 237px;
  height: 300px;
  margin-right: 10px;
  margin-bottom: 10px;
}

.goods-item {
  width: 237px;
  height: 300px;
  padding: 10px 30px;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
  transition: all 0.5s;
}

.goods-item:hover {
  border: 1px solid #27ba9b;
}

.goods-item .image {
  display: block;
  width: 160px;
  height: 160px;
  margin: 0 auto;
}

.goods-item .image img {
  width: 100%;
  height: 100%;
}

.goods-item p.name {
  height: 44px;
}
.goods-item p {
  margin-top: 6px;
  font-size: 16px;
}

.ellipsis,
.ellipsis-2 {
  text-overflow: ellipsis;
  overflow: hidden;
}

.ellipsis-2 {
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.ellipsis {
  white-space: nowrap;
}

.goods-item p.desc {
  color: #666;
  height: 22px;
}
.goods-item p {
  margin-top: 6px;
  font-size: 16px;
}

.goods-item p.price {
  margin-top: 10px;
  font-size: 20px;
  color: #cf4444;
}

.goods-item .extra {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 86px;
  width: 100%;
  background: #27ba9b;
  text-align: center;
  transform: translate3d(0, 100%, 0);
  transition: all 0.5s;
}

.goods-item:hover .extra {
  transform: none;
}

.goods-item .extra span:first-child {
  font-size: 18px;
  border-bottom: 1px solid #fff;
  line-height: 40px;
  margin-top: 5px;
}

.goods-item .extra span {
  display: block;
  color: #fff;
  width: 120px;
  margin: 0 auto;
  line-height: 30px;
}


.tit{
  background:#f5f5f5;
}

.special-list {
    height: 380px;
    padding-bottom: 20px;
    display: flex;
    justify-content: space-between;
}

.special-list .special-item {
    width: 404px;
    background: #fff;
    transition: all .5s;
}

.special-list .special-item:hover {
    transform: translate3d(0,-3px,0);
    box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
}

.special-list .special-item a{
    display: block;
    width: 100%;
    height: 288px;
    position: relative;
}

.special-list .special-item a img{
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
    object-fit: cover;
}

.special-list .special-item a .meta{
    background-image: linear-gradient(0deg,rgba(0,0,0,.8),transparent 50%);
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 288px;
}

.special-list .special-item a .meta .title{
    position: absolute;
    bottom: 0;
    left: 0;
    padding-left: 16px;
    width: 70%;
    height: 70px;
}

.special-list .special-item a .meta .title .top{
    color: #fff;
    font-size: 22px;
    display: block;
}

.special-list .special-item a .meta .title .sub{
    display: block;
    font-size: 19px;
    color: #999;
}

.special-list .special-item a .meta .price{
    position: absolute;
    bottom: 25px;
    right: 16px;
    line-height: 1;
    padding: 4px 8px 4px 7px;
    color: #cf4444;
    font-size: 17px;
    background-color: #fff;
    border-radius: 2px;
}

.special-list .special-item .foot{
    height: 72px;
    line-height: 72px;
    padding: 0 20px;
    font-size: 16px;
}

.special-list .special-item .foot .like, .special-list .special-item .foot .view {
    float: left;
    margin-right: 25px;
    vertical-align: middle;
}

.special-list .special-item .foot .reply{
    float: right;
    vertical-align: middle;
}

.special-list .special-item .foot i {
    display: inline-block;
    width: 15px;
    height: 14px;
    margin-right: 5px;
    color: #999;
}





.container {
  width: 1240px;
  margin: 0 auto;
  position: relative;
}
</style>